package com.rest.demo.functional.strean;

import java.util.stream.IntStream;

/**
 * @author Administrator
 * @decription
 * @Date 2018-01-30 13:47
 */
public class SumStream {
    public static void main(String[] args) {
        System.out.println(sum(1,100));
        System.out.println(sum2(1,100));
    }

    public static Integer sum(Integer start,Integer end) {
        return IntStream.range(start,end+1).reduce(0,(a,b) -> a + b);
    }

    public static Integer sum2(Integer start,Integer end) {
        return IntStream.range(start,end+1).filter(n -> n % 2 == 0).reduce(0,(a,b) -> a + b);
    }
}
